﻿using Abp.IdentityFramework;
using Abp.UI;
using Abp.WebApi.Controllers;
using Microsoft.AspNet.Identity;

namespace FutureApp.Api.Controllers
{
    /// <summary>
    /// API controller base
    /// </summary>
    public abstract class FutureAppApiControllerBase : AbpApiController
    {
        /// <summary>
        /// 初始化
        /// </summary>
        protected FutureAppApiControllerBase()
        {
            this.LocalizationSourceName = FutureAppConsts.LocalizationSourceName;            
        }

        /// <summary>
        /// 检查实体状态
        /// </summary>
        protected virtual void CheckModelState()
        {
            if (!this.ModelState.IsValid)
            {
                throw new UserFriendlyException(L("InvalidFormData"));
            }
        }

        /// <summary>
        /// 校验结果，错误则抛出异常
        /// </summary>
        /// <param name="identityResult">身份验证结果</param>
        protected void CheckErrors(IdentityResult identityResult)
        {
            identityResult.CheckErrors(this.LocalizationManager);
        }
    }
}
